package com.goodving.guli.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.support.v4.app.TaskStackBuilder;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.goodving.guli.R;
import com.goodving.guli.view.C0804t;
import com.goodving.guli.view.HomeKeyReceiver;

/**
 * Created by john on 2015/11/26.
 */
public abstract class BaseActivity extends Activity {
    public static final int MI_NOTE_APP_DPI = 480;
    public static final int MI_NOTE_ORIGINAL_DPI = 440;
    protected TextView mHomeBack;
    private HomeKeyReceiver mHomeKeyReceiver;

    class C1844o implements View.OnClickListener {
        final /* synthetic */ BaseActivity f10296a;

        C1844o(BaseActivity baseActivity) {
            this.f10296a = baseActivity;
        }

        public void onClick(View view) {
            this.f10296a.onHomeBackPressed();
        }
    }

    private void initHomeBack() {
        this.mHomeBack = (TextView) findViewById(R.id.home_back);
        if (this.mHomeBack != null) {
            this.mHomeBack.setOnClickListener(new C1844o(this));
            if (C0804t.m8835a() && !isExceptForMiNote()) {
                this.mHomeBack.setTextSize(14.0f);
            }
        }
    }

    public void finish() {
        Intent b = NavUtils.getParentActivityIntent(this);
        if (b == null || !NavUtils.shouldUpRecreateTask((Activity) this, b)) {
            super.finish();
        } else {
            TaskStackBuilder.create((Context) this).addNextIntentWithParentStack(b).startActivities();//m1109b(b).m1110b();
        }
    }

    protected boolean isExceptForMiNote() {
        return false;
    }

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        if (C0804t.m8839d(this)) {
            if (isExceptForMiNote()) {
                C0804t.m8829a((Context) this, (int) MI_NOTE_ORIGINAL_DPI);
            } else {
                C0804t.m8829a((Context) this, (int) MI_NOTE_APP_DPI);
            }
        }
        IntentFilter intentFilter = new IntentFilter("android.intent.action.CLOSE_SYSTEM_DIALOGS");
        this.mHomeKeyReceiver = new HomeKeyReceiver();
        registerReceiver(this.mHomeKeyReceiver, intentFilter);
    }

    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(this.mHomeKeyReceiver);
    }

    protected void onHomeBackPressed() {
        finish();
    }

    protected void onNewIntent(Intent intent) {
//        if (Config.m8876h().f4193c.f4248d.booleanValue()) {
//            BindQQHealthActivity.m13673a((Activity) this, intent);
//        }
    }

    protected void onResume() {
        super.onResume();
//        if (Config.m8876h().f4193c.f4248d.booleanValue()) {
//            BindQQHealthActivity.m13673a((Activity) this, getIntent());
//            BindQQHealthActivity.m13669a((Activity) this);
//        }
    }

    public void setContentView(int i) {
        super.setContentView(i);
        initHomeBack();
    }

    public void setContentView(View view) {
        super.setContentView(view);
        initHomeBack();
    }

    public void setContentView(View view, ViewGroup.LayoutParams layoutParams) {
        super.setContentView(view, layoutParams);
        initHomeBack();
    }

    protected void updateTitle(int i) {
        this.mHomeBack.setText(i);
    }

    protected void updateTitle(String str) {
        this.mHomeBack.setText(str);
    }
}
